from setuptools import setup, find_packages
#from distutils.core import setup
from numpy.distutils.extension import Extension
from Cython.Distutils import build_ext
import mpi4py

mpi_inc_dirs = []
mpi_compile_args = []
mpi_link_args = []

HAS_MPI4PY = True
try:
    import mpi4py
    # assume a working mpi environment
    import commands
    mpic = 'mpicc'
    mpi_link_args.append(commands.getoutput(mpic + ' --showme:link'))
    mpi_compile_args.append(commands.getoutput(mpic +' --showme:compile'))
    mpi_inc_dirs.append(mpi4py.get_include())
except ImportError:
    HAS_MPI4PY = False

ext_modules = [Extension("v3dsolver.vector", 
                        ["src/v3dsolver/vector.pyx"]),
               Extension("v3dsolver.intvector", 
                        ["src/v3dsolver/intvector.pyx"]),
               Extension("v3dsolver.lpsolver", 
                        ["src/v3dsolver/lpsolver.pyx","src/v3dsolver/lpsolver_c.C"],
                        language="c++"),
               Extension("v3dsolver.boundary_manager", 
                        ["src/v3dsolver/boundary_manager.py"]),
               Extension("v3dsolver.fluid_elements.fluid_elems", 
                        ["src/v3dsolver/fluid_elements/fluid_elems.py"]),
               Extension("v3dsolver.tree_manager.distribution_manager", 
                        ["src/v3dsolver/tree_manager/distribution_manager.py"]),
               Extension("v3dsolver.tree_manager.tree_manager", 
                        ["src/v3dsolver/tree_manager/tree_manager.py"]),
               Extension("v3dsolver.tree_manager.vel_calculator", 
                        ["src/v3dsolver/tree_manager/vel_calculator.py"]),
               Extension("v3dsolver.advection_manager", 
                        ["src/v3dsolver/advection_manager.py"]),
               Extension("v3dsolver.stretching_manager", 
                        ["src/v3dsolver/stretching_manager.py"]),
               Extension("v3dsolver.diffusion_manager", 
                        ["src/v3dsolver/diffusion_manager_puLP.pyx"]),
               Extension("v3dsolver.neighbour_finder", 
                        ["src/v3dsolver/neighbour_finder.py"]),
               Extension("v3dsolver.merging_manager", 
                        ["src/v3dsolver/merging_manager.py"]),
               Extension("v3dsolver.annihilation_manager", 
                        ["src/v3dsolver/annihilation_manager.py"]),
               Extension("v3dsolver.vorticity_interpolator", 
                        ["src/v3dsolver/vorticity_interpolator.py"]),
               Extension("v3dsolver.tree_manager.spherical_t_design", 
                        ["src/v3dsolver/tree_manager/spherical_t_design.py"])]

for extn in ext_modules:
    extn.include_dirs.extend(mpi_inc_dirs)
    extn.extra_compile_args.extend(mpi_compile_args)
    extn.extra_link_args.extend(mpi_link_args)

setup(name='v3dsolver',
      version='0.1',
      description='3D Vortex Solver',
      author='Prashant Agrawal',
      author_email='agrawal.prash@gmail.com',
      packages = find_packages('src'),
      cmdclass = {'build_ext': build_ext},
      ext_modules = ext_modules,
      package_dir = {'': 'src'},
     )
